package com.gnizr.db.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Comment implements Serializable {
	/**
	 *  Author: Jason Braun
	 */
	private static final long serialVersionUID = -7776863251954299926L;
	
	
	
	private int id;
	private User author;
	private String text;
	private int bookmarkID;
	private int rank;
	private Date createdOn;
	private Date lastUpdated;

	/**
	 * Creates a new instance of this class. 
	 */
	public Comment(){	
		this.text = "";
	}
	
	/**
	 * Creates a new instance of this class with a specific <code>id</code>.
	 * @param id the ID of this comment
	 */
	public Comment(int id){
		this();
		this.id = id;
	}
	
	/**
	 * Creates a new instance of this class and intitializes
	 * values that describe the comment owner and the comment URL. 
	 * @param user the user who owns this comment.
	 * @param link the URL that the user has commented.
	 */
	public Comment(User user, int bookmarkID){				
		this();
		this.author = new User(user);
		this.bookmarkID = bookmarkID;
	}
	/**
	 * Returns the bookmarkID of the <cod>bookmark</code> this comment is associated with
	 * 
	 * @return the bookmarkID of this comment.
	 */
	public int getBookmarkID() {
		return bookmarkID;
	}
	/**
	 * Sets the bookmarkID of the <cod>bookmark</code> this comment is associated with
	 * 
	 * @param the bookmarkID of this comment.
	 */
	public void setBookmarkID(int bookmarkID) {
		this.bookmarkID = bookmarkID;
	}

	 
	/**
	 * Returns the date/time when the comment is created.
	 * 
	 * @return the creation date/time of this comment.
	 */
	public Date getCreatedOn() {
		return createdOn;
	}
	
	/**
	 * Sets the date/time when the comment is created.
	 * 
	 * @param createdOn date/time when this comment is created.
	 */
	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}
	
	/**
	 * Returns the ID of this comment
	 * @return comment ID.
	 */
	public int getId() {
		return id;
	}
	
	/**
	 * Sets the ID of this comment
	 * @param id comment ID.
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	/**
	 * Returns the date/time when any properties of this comment
	 * has been changed.
	 * 
	 * @return the last updated date/time of this comment.
	 */
	public Date getLastUpdated() {
		return lastUpdated;
	}
	
	/**
	 * Sets the last updated date/time of this comment.
	 * 
	 * @param lastUpdated when this comment was last updated.
	 */
	public void setLastUpdated(Date lastUpdated) {
		this.lastUpdated = lastUpdated;
	}
	
	/**
	 * Returns the comment text
	 * 
	 * @return comment text
	 */
	public String getText() {
		return text;
	}
	
	/**
	 * Sets the text for this comment.
	 * 
	 * @param text = comment text.
	 */
	public void setText(String text) {
		this.text = text;
	}
	
	/**
	 * Returns the <code>Link</code> object reprsentation of the comment URL.
	 * @return comment url.
	 */
	public int getRank() {
		return rank;
	}
	
	/**
	 * Sets the comment URL, as <code>Link</code> object, of this comment. 
	 * @param link comment url.
	 */
	public void setRank(int rank) {
		this.rank = rank;
	}
	
	/**
	 * Returns the author user of this comment.
	 * @return comment author.
	 */
	public User getAuthor() {
		return author;
	}
	
	/**
	 * Sets the owner user of this comment.
	 * 
	 * @param user comment user.
	 */
	public void setAuthor(User user) {
		this.author = user;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = super.hashCode();
		result = PRIME * result + ((createdOn == null) ? 0 : createdOn.hashCode());
		result = PRIME * result + id;
		result = PRIME * result + ((lastUpdated == null) ? 0 : lastUpdated.hashCode());
		result = PRIME * result + rank;
		result = PRIME * result + ((text == null) ? 0 : text.hashCode());
		result = PRIME * result + ((author == null) ? 0 : author.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		final Comment other = (Comment) obj;
		if (createdOn == null) {
			if (other.createdOn != null)
				return false;
		} else if (!createdOn.equals(other.createdOn))
			return false;
		if (id != other.id)
			return false;
		if (lastUpdated == null) {
			if (other.lastUpdated != null)
				return false;
		} else if (!lastUpdated.equals(other.lastUpdated))
			return false;
		if (rank != other.rank)
			return false;
		if (text == null) {
			if (other.text != null)
				return false;
		} else if (!text.equals(other.text))
			return false;
		if (author == null) {
			if (other.author != null)
				return false;
		} else if (!author.equals(other.author))
			return false;
		return true;
	}

	@Override
	public String toString() {
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("id",getId());
		map.put("author",getAuthor());
		map.put("rank",getRank());
		map.put("text",getText());
		map.put("createdOn",getCreatedOn());
		map.put("lastUpdted",getLastUpdated());	
		return map.toString();
	}



	
}
